using System;
using System.Web.UI;
using System.Web.UI.WebControls;

using EntLibEC.Cmn;
using EntLibEC.Biz;

namespace EntLibEC.View.Cmn
{
	/// <summary>
	/// Summary description for TransferItemType.
	/// </summary>
	public class TransferItemType : Control, INamingContainer 
	{
		private DropDownList ddl = new DropDownList();

		protected void Bind(bool isAll)
		{
			if ( !Page.IsPostBack )
			{
				ddl.Items.Clear();
				ddl.DataSource = AppEnum.GetTransferItemType();
				ddl.DataValueField = "key";
				ddl.DataTextField = "value";
				ddl.DataBind();
				if ( isAll )
					ddl.Items.Insert( 0,new ListItem(AppConst.AllSelectString,AppConst.IntNull.ToString()) );

			}
		}

		protected override void OnInit(EventArgs e)
		{
			ddl.AutoPostBack = true;
			ddl.SelectedIndexChanged += new System.EventHandler(ddl_SelectedIndexChanged);

			Controls.Add(ddl);

			Bind(false);

			base.OnInit(e);
		}
      
		public void ddl_SelectedIndexChanged(object sender, System.EventArgs e)
		{

			if (SelectedIndexChanged != null)
				SelectedIndexChanged(this, EventArgs.Empty);
		}


		public int TypeSysNo
		{
			get
			{
				return Convert.ToInt32(ddl.SelectedItem.Value);
			}
			set
			{
				ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(value.ToString()) );
			}
		}

		public bool Enabled
		{
			set
			{
				ddl.Enabled = value;
			}
		}

		public event EventHandler SelectedIndexChanged;
	}
}
